package pokerSaloon.vue;
import pokerSaloon.controller.CreationPartieController;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * fenCreer.java
 *
 * Created on 28 févr. 2010, 16:54:23
 */

/**
 *
 * @author animateur
 */
public class fenCreer extends javax.swing.JFrame implements View {

    /**
	 * 
	 */
	private static final long serialVersionUID = 7431140832463506568L;
	private CreationPartieController controller;
    
	/** Creates new form fenCreer */
    public fenCreer(CreationPartieController controller) {
    	this.controller = controller;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {

        btnCreer = new javax.swing.JButton();
        menuMaxJoueurs = new javax.swing.JComboBox();
        labelJoueursMax = new javax.swing.JLabel();
        labelNom = new javax.swing.JLabel();
        saisieNom = new javax.swing.JTextField();
        btnAnnuler = new javax.swing.JButton();
        menuPrincipal = new javax.swing.JMenuBar();
        menuPokerSaloon = new javax.swing.JMenu();
        menuItemCreer = new javax.swing.JMenuItem();
        menuItemAnnuler = new javax.swing.JMenuItem();
        separateur = new javax.swing.JPopupMenu.Separator();
        menuItemQuitter = new javax.swing.JMenuItem();
        menuAide = new javax.swing.JMenu();
        menuItemManuel = new javax.swing.JMenuItem();
        MenuItemAPropos = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Poker Saloon - Cr\u00E9ation de partie");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        btnCreer.setText("Cr\u00E9er la partie");
        btnCreer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCreerActionPerformed(evt);
            }
        });

        menuMaxJoueurs.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2", "3", "4", "5", "6", "7", "8", "9", "10" }));

        labelJoueursMax.setText("Nombre de joueurs  :");

        labelNom.setText("Nom de la partie : ");

        saisieNom.setToolTipText("Saisissez le nom de la partie");

        btnAnnuler.setText("Annuler");
        btnAnnuler.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnnulerActionPerformed(evt);
            }
        });

        menuPokerSaloon.setText("Poker Saloon");
        menuPokerSaloon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuPokerSaloonActionPerformed(evt);
            }
        });

        menuItemCreer.setText("Créer la partie");
        menuItemCreer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemCreerActionPerformed(evt);
            }
        });
        menuPokerSaloon.add(menuItemCreer);

        menuItemAnnuler.setText("Annuler");
        menuPokerSaloon.add(menuItemAnnuler);
        menuPokerSaloon.add(separateur);

        menuItemQuitter.setText("Quitter");
        menuItemQuitter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemQuitterActionPerformed(evt);
            }
        });
        menuPokerSaloon.add(menuItemQuitter);

        menuPrincipal.add(menuPokerSaloon);

        menuAide.setText("Aide");

        menuItemManuel.setText("Manuel d'utilisation");
        menuAide.add(menuItemManuel);

        MenuItemAPropos.setText("A propos");
        MenuItemAPropos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemAProposActionPerformed(evt);
            }
        });
        menuAide.add(MenuItemAPropos);

        menuPrincipal.add(menuAide);

        setJMenuBar(menuPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelJoueursMax)
                    .addComponent(labelNom))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(menuMaxJoueurs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saisieNom, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(117, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(158, Short.MAX_VALUE)
                .addComponent(btnAnnuler)
                .addGap(18, 18, 18)
                .addComponent(btnCreer)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNom)
                    .addComponent(saisieNom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelJoueursMax)
                    .addComponent(menuMaxJoueurs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 142, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCreer)
                    .addComponent(btnAnnuler))
                .addContainerGap())
        );

        pack();
    }

    private void menuItemCreerActionPerformed(java.awt.event.ActionEvent evt) {
        btnCreer.doClick();
    }

    private void menuItemQuitterActionPerformed(java.awt.event.ActionEvent evt) {
        OutilsInterface.quitter(this);
    }

    private void MenuItemAProposActionPerformed(java.awt.event.ActionEvent evt) {
        OutilsInterface.aPropos(this);
    }

    private void btnAnnulerActionPerformed(java.awt.event.ActionEvent evt) {
        controller.retourListe();
    }

    private void btnCreerActionPerformed(java.awt.event.ActionEvent evt) {       
        controller.creerPartie(saisieNom.getText(), menuMaxJoueurs.getSelectedIndex()+2);
    }

    private void menuPokerSaloonActionPerformed(java.awt.event.ActionEvent evt) {
        btnAnnuler.doClick();
    }
    
    private void formWindowClosing(java.awt.event.WindowEvent evt) {
       controller.deconnexion();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    /**
	 * @uml.property  name="menuItemAPropos"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuItem MenuItemAPropos;
    /**
	 * @uml.property  name="btnAnnuler"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JButton btnAnnuler;
    /**
	 * @uml.property  name="btnCreer"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JButton btnCreer;
    /**
	 * @uml.property  name="labelJoueursMax"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JLabel labelJoueursMax;
    /**
	 * @uml.property  name="labelNom"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JLabel labelNom;
    /**
	 * @uml.property  name="menuAide"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenu menuAide;
    /**
	 * @uml.property  name="menuItemAnnuler"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuItem menuItemAnnuler;
    /**
	 * @uml.property  name="menuItemCreer"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuItem menuItemCreer;
    /**
	 * @uml.property  name="menuItemManuel"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuItem menuItemManuel;
    /**
	 * @uml.property  name="menuItemQuitter"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuItem menuItemQuitter;
    /**
	 * @uml.property  name="menuMaxJoueurs"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JComboBox menuMaxJoueurs;
    /**
	 * @uml.property  name="menuPokerSaloon"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenu menuPokerSaloon;
    /**
	 * @uml.property  name="menuPrincipal"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuBar menuPrincipal;
    /**
	 * @uml.property  name="saisieNom"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JTextField saisieNom;
    /**
	 * @uml.property  name="separateur"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JPopupMenu.Separator separateur;
    

	@Override
	public void displayView() {
		this.setVisible(true);
	}

	@Override
	public void removeView() {
		this.dispose();		
	}

	public void afficheMsgDialog(String message, String titre) {
		 javax.swing.JOptionPane.showMessageDialog(this, message,titre,2);
	}

}
